<template>

  <div class="order">
    <div class="msg ">
      <div class="order_list">
        <div class="weui-media-box weui-media-box_appmsg" v-for="item in orderDetailList">
          <img src="../../assets/yishiyong.png" alt="" width="55" height="55" class="shuiyin" v-if="item.goodState==2">
          <img src="../../assets/yiguoqi.png" alt="" width="55" height="55" class="shuiyin" v-if="item.goodState==1">
          <div class="weui-media-box__hd">
            <img :src="src" alt="" class="weui-media-box__thumb" v-if="orderType==6">
            <img :src="item.coverImg | imgPathFilter" alt="" class="weui-media-box__thumb" v-else>
          </div>
          <div class="weui-media-box__bd">
            <h4 class="weui-media-box__title" v-if="orderType==6">充值订单</h4>
            <h4 class="weui-media-box__title" v-else>{{item.goodsName}}</h4>
            <p class="weui-media-box__desc">{{item.unitPrice}}元</p>
          </div>
          <span class="num">×{{item.buyNum}}</span>
        </div>
      </div>
    </div>

    <div class="divider"></div>
    <ul class="msg">
      <li>订单编号：{{order.orderNo}}</li>
      <li>订单时间：{{order.createDate}}</li>
      <li>支付时间：{{order.payDate}}</li>
      <li v-if="order.payType=='PAY_WX'">支付方式：微信</li>
      <li v-if="order.payType=='PAY_ALI'">支付方式:支付宝</li>
      <li v-if="order.payType=='PAY_UNDERLINE'">支付方式：线下</li>
      <li>支付总额：{{order.totalPrice}}元</li>
    </ul>
    <div class="divider"></div>
    <div class="list" v-show="isShowQr">
      <ul>
        <li>二维码</li>
        <li>
          <div id="qrCode" style="width: 100px;height: 100px"></div>
        </li>
        <li>{{agentCodeStr}}</li>
      </ul>
    </div>
    <div class="divider"></div>
    <ul class="msg">
      <li>使用说明</li>
      <li>1.使用贵宾厅时，您可将核验二维码出示给机场工作人员即可；</li>
      <li>2.转赠他人使用贵宾厅时，您可点击上方“发送短信”按钮，添加接收人手机号码可将贵宾厅核验二维码发送；</li>
    </ul>
    <p class="offer" @click="goIndex()">返回首页</p>
  </div>

</template>

<script type="text/ecmascript-6">
  import {getOrderDetail} from '../../utils/http'
  import QRCode from 'qrcodejs2';
  import {Toast} from 'we-vue'

  export default {
    name: 'allorderdetail',
    props: {},
    data() {
      return {
        isUse: false,
        orderDetailList: [],
        order: {},
        imageBase64QRCode: '',
        accountGoodsQrCode: '',
        isUse: false,
        isShowQr: true,
        src: require('../../assets/wallet.png'),
        orderType: 0
      };
    },
    methods: {
      generateQrCode(text) {
        new QRCode('qrCode', {
          width: 100,
          height: 100,        // 高度
          text: text,   // 二维码内容
          render: 'canvas',   // 设置渲染方式（有两种方式 table和canvas，默认是canvas）
          background: '#f0f',   // 背景色
          foreground: '#ff0'    // 前景色
        })
      },
      getOrderDetailData(params) {
        getOrderDetail(params).then(res => {
          console.log(res);
          if (res.code == 100) {
            this.orderDetailList = res.object.orderDetailList;
            this.order = res.object.order;
            let orderDetailLength = this.orderDetailList.length;
            if (orderDetailLength == 1) {
              let orderDetail = this.orderDetailList[0];
              let orderType = orderDetail.orderType;
              this.orderType = orderType;
              if (orderType != 1) {
                this.isShowQr = false;
              }
            }
            this.imageBase64QRCode = res.object.imageBase64QRCode;
            this.accountGoodsQrCode = res.object.accountGoodsQrCode;
            this.generateQrCode(this.accountGoodsQrCode);
          }
        })
      },
      goIndex() {
        this.$router.push({path: '/index'});
      }
    },
    created() {
      let orderId = this.$route.query.orderId;
      this.getOrderDetailData({orderId: orderId});
    },
    computed: {
      agentCodeStr: function () {
        return this.$myUtils.replaceStr(this.accountGoodsQrCode)
      }
    }

  }
</script>

<style scoped lang="less" rel="stylesheet/less">
  .msg {
    position: relative;
    padding: 0 10px 10px;

    .order_list {
      position: relative;

      .shuiyin {
        position: absolute;
        top: 10px;
        right: 0;
      }
    }

    .order_list:not(:last-of-type) {
      padding-bottom: 10px;
      border-bottom: 1px solid #eee;
    }

    .all {
      border-top: 1px solid #eee;
      padding-top: 10px;
      margin-top: 10px;

      .money {
        color: #ff8551;
        float: left;
        margin-top: 5px;
      }
    }

    .state {
      color: #e96774;
      font-size: 12px;
      margin-left: 5px;
    }

    .yuyueing {
      font-size: 10px;
      color: #fff;
      background-color: #ccc;
      border-radius: 25px;
      padding: 5px 15px;
      margin-left: 5px;
    }

    .suc {
      background-color: #3095f0;
    }

    .fail {
      background-color: #e96775;
    }

    .num {
      font-size: 15px;
      color: #666;
      margin-top: 35px;
    }

    .status {
      font-size: 12px;
      text-align: right;
      padding-right: 15px;

      .success {
        color: #999;
      }

      .daifu {
        color: #ff8551;
      }

      button {
        border-radius: 25px;
        display: inline-block;
        width: 72px;
        font-size: 15px;
        color: #111;
        margin-left: 10px;
        line-height: 1.6
      }
    }
  }

  .weui-btn {
    padding: 0 5px;
  }

  .weui-btn + .weui-btn {
    margin-top: 0;
  }

  .list {
    width: 80%;
    margin: auto;
    background-size: 100% 100%;

    ul {
      color: #111;
      font-size: 13px;
      padding: 30px;
      text-align: center;

      li:first-child {
        margin-bottom: 20px;
      }

      li:nth-child(2) {
        div {
          margin: 0 auto;
          border: 1px solid #f6fffc;
        }
      }

      li:last-child {
        margin-top: 5px;
        font-size: 18px;
      }
    }

  }

  .divider {
    background-color: #eee;
    height: 10px;
  }

  .msg {
    padding: 10px;
    font-size: 13px;
    color: #666;
    line-height: 30px;
    text-align: left;
  }

  .offer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-image: linear-gradient(to left, #4c92ed, #61beec);
    height: 50px;
    line-height: 50px;
    color: #fff;
    z-index: 999;
  }
</style>
